package cn.bgs.controller;

import cn.bgs.pojo.Building;
import cn.bgs.pojo.CommunityVo;
import cn.bgs.pojo.Portal;
import cn.bgs.service.InfoService;
import cn.bgs.utils.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("info")
public class InfoController {
    @Autowired
    private InfoService infoService;
    @GetMapping("findinfo")
    public PageInfo<CommunityVo> findinfo (String communityId ,String houseuse,String howmany,Integer pagesize,Integer pagenow){
         PageInfo<CommunityVo> page = infoService.page1(communityId,houseuse,howmany,pagesize,pagenow);
        return page;
    }
    @GetMapping("findhouse")
    public PageInfo<CommunityVo> findhouse (String communityId,String houseuse,String state,Integer pagesize,Integer pagenow){
        PageInfo<CommunityVo> pages = infoService.page2(communityId,houseuse,state,pagesize,pagenow);
        return pages;
    }
    @PostMapping("addCommunity")
    public R addCommunity(@RequestBody Building forms){
        infoService.addCommunity(forms);
        return R.ok();
    }
    @GetMapping("del")
    public R del(Integer id){
        infoService.del(id);
        return R.ok();
    }
    @PostMapping("updatebuilding")
    public R updatebuilding(@RequestBody Building formData){
        infoService.updatebuilding(formData);
        return R.ok();
    }
    @PostMapping("load")
    public R load(Integer id){
        List<Building> building = infoService.load(id);
        return R.ok().data("data",building);
    }
    @PostMapping("addportal")
     public R addportal(@RequestBody Portal forms){
        infoService.addportal(forms);
        return R.ok();
    }
    @GetMapping("delportal")
    public R delportal(Integer id){
        infoService.delportal(id);
        return R.ok();
    }
}